package dao

import "WORKSPACE/models"

func GetAllconsumer() (error, []models.Consumer, int64) {
	var consumerData []models.Consumer
	//page := consumerParam["page"].(int)
	//pageSize := consumerParam["limit"].(int)
	//searchName := consumerParam["searchName"].(string)
	var total int64
	err := db.Table("consumer").Where("is_del = ?", "f").Order("consumer_id ASC").Count(&total).Find(&consumerData).Error
	return err, consumerData, total
}

func Addconsumer(consumer models.Consumer) error {
	err := db.Table("consumer").Select("consumer_id","consumer_name","consumer_address","consumer_postcode","consumer_phone").Create(&consumer).Error
	return err
}

func Updateconsumer(consumer models.Consumer) error {
	err := db.Table("consumer").Where("consumer_id = ?", consumer.Consumer_id).Updates(&consumer).Error
	return err
}

func Delconsumer(id int) error {
	err := db.Table("consumer").Where("consumer_id = ?", id).Update("is_del",true).Error
	return err
}